list LocationName;
list LocationPos;
key User;
string Sorted;
integer menu_handler;
integer menu_channel;
integer chan = -658572700;
string object = "Beam";
vector relativePosOffset = <1.0, 0.0, 0.2>;
rotation relativeRot = <0.0, 0.0, 0.0, 0.0>;
integer startParam = 10;

menu(key user,string title,list buttons)
{
    menu_channel = (integer)(llFrand(99999.0) * -1);
    menu_handler = llListen(menu_channel,"","","");
    llDialog(user,title,buttons,menu_channel);
    llSetTimerEvent(3.0);
}

default
{
    state_entry()
    {
        llListen(chan,"","","");
        llRequestPermissions(llGetOwner(),PERMISSION_TRACK_CAMERA);
    }
    
    link_message(integer sender_num, integer num, string msg, key id) 
    {      
        if( msg == "reset" )
        {
             llResetScript();
        }
    }
    
    on_rez(integer start_param)
    {
        llResetScript();
    }
    
    attach(key id)
    {
        if(id)//tests if it is a valid key and not NULL_KEY
        {
            llResetScript();
        }
    }
    
    changed(integer change)
    {
        if (change & CHANGED_INVENTORY)
        {
            llResetScript();
        }
    }
    
    timer()
    {
        integer ListLength = llGetListLength(LocationName);
        if (ListLength <= 11)
        {
            if (ListLength > 0)
            {
                LocationName = LocationName + "CAMERA";
                menu(User,"\nChose your destination.",LocationName);
            }
            else
            {
                menu(User,"\nNo Destinations Found",["OK", "CAMERA"]);
            }
        }
        else if (ListLength > 11)
        {
            llOwnerSay("ERROR: There Are " + (string)ListLength + " Locations In Range, Only 11 May Be In Range At A Time, Please Delete Some");
        }
        llSetTimerEvent(0.0);
    }
    listen(integer channel, string name,key id, string message)
    {
        if(channel == chan)
        {
            list UnSorted;
            UnSorted = llParseString2List(message,["|"],[""]);
            Sorted = llList2String(UnSorted, 0);
            if(Sorted == "menu")
            {

                if(llList2String(UnSorted, 1) == llGetOwner())
                {
                    User = llGetOwner();
                    LocationName = [];
                    LocationPos=[];
                    llRegionSay(chan,"Update");
                    llSetTimerEvent(1.5);
                }
            }
            else if(Sorted == "location")
            {

                LocationName = LocationName+=(list)llList2String(UnSorted, 1);
                LocationPos = LocationPos+=(list)llList2String(UnSorted,2);
                UnSorted = [];
            }
        }
        else if(channel == menu_channel)
        {
            if(message != "OK")
            {
                list Loc;
                string Pos;
                integer LocDescNumber = (integer)llListFindList(LocationName,(list)message);
                Pos = llList2String(LocationPos, LocDescNumber);
                if(message == "CAMERA")
                {
                    Pos = "";
                    Pos = (string)llGetCameraPos();
                }
                llWhisper(-658572700,"ClearBeam||HUD");
                if(Pos != "")
                {
                    vector myPos = llGetPos();
                    rotation myRot = llGetRot();
                    vector rezPos = myPos+relativePosOffset*myRot;
                    rotation rezRot = relativeRot*myRot;
                    llRezObject(object, rezPos, ZERO_VECTOR, rezRot, startParam);
                    llSleep(1.0);
                    llWhisper(-658572700,"||warp||"+Pos");
                }
            }
        }
    }
}